const { Result } = require("@/libs/result");
const productService = require("./product.service");

function validatorResult(ctx) {
  return new Promise(async (resolve) => {
    try {
      const data = await ctx.getValidationResult();
      resolve([false, data]);
    } catch (err) {
      resolve([err, null]);
    }
  });
}

class ProductController {
  async queryProductList(ctx) {
    ctx.body = await productService.queryProductList(ctx.request.query);
  }
  async createProduct(ctx) {
    ctx.body = await productService.createProduct(ctx.request.body);
  }
  async getProduct(ctx) {
    ctx.body = await productService.getProduct(ctx.request.params);
  }
  async deleteProduct(ctx) {
    ctx.body = await productService.deleteProduct(ctx.request.params);
  }
  async updateProduct(ctx) {
    ctx.body = await productService.updateProduct(ctx.request.params, ctx.request.body);
  }


  async createProductCategory(ctx) {
    ctx.body = await productService.createProductCategory(ctx.request.body);
  }
  async getProductCategory(ctx) {
    ctx.body = await productService.getProductCategory(ctx.request.params);
  }
  async updateProductCategory(ctx) {
    ctx.body = await productService.updateProductCategory(ctx.request.params, ctx.request.body);
  }
  async deleteProductCategory(ctx) {
    ctx.body = await productService.deleteProductCategory(ctx.request.params, ctx.state);
  }


  async queryProductCategoryList(ctx) {
    ctx.body = await productService.queryProductCategoryList(ctx.request.body, ctx.state);
  }
  async createProductUnit(ctx) {
    ctx.body = await productService.createProductUnit(ctx.request.body, ctx.state);
  }
  async updateProductUnit(ctx) {
    ctx.body = await productService.updateProductUnit(ctx.request.params, ctx.request.body);
  }
  async deleteProductUnit(ctx) {
    ctx.body = await productService.deleteProductUnit(ctx.request.params);
  }
  async queryProductUnitList(ctx) {
    ctx.body = await productService.queryProductUnitList(ctx.request.body, ctx.state);
  }
  async getProductUnit(ctx) {
    ctx.body = await productService.getProductUnit(ctx.request.params, ctx.state);
  }
}

module.exports = new ProductController();
